<template>
  <div>
    <el-dialog
      v-model="open"
      :before-close="cancle"
      :title="title"
      fullscreen
    >
      <el-form
        ref="updateForms"
        v-loading="loading"
        inline
        label-width="120px"
        class="queryParams"
        :model="updateForm"
      >
        <el-row>
          <el-col :span="24">
            <el-row>
              <el-col :span="24" class="mb8">
                <div>基本信息</div>
              </el-col>
              <el-form-item label="系统订单号" prop="orderNo">
                <el-input
                  v-model="updateForm.orderNo"
                  
                  disabled
                ></el-input>
              </el-form-item>
              <el-form-item label="报价类型" prop="quotationType">
                <el-select
                  v-model="updateForm.quotationType"
                  filterable 
                  disabled
                >
                  <el-option
                    v-for="dict in dicts[DictDirection.报价类型]"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item v-if="updateForm.quotationType != 3" :label="labels" prop="customPrice">
                <el-input
                  v-model="updateForm.customPrice"
                  clearable
                
                  placeholder="请输入价格"
                ></el-input>
              </el-form-item>
              <el-form-item label="签入员" prop="checkInMer">
                <el-input v-model="updateForm .checkInMer" disabled></el-input>
              </el-form-item>
              <el-form-item label="业务员：" prop="businessManager">
                <el-input v-model="updateForm.businessManager" disabled></el-input>
              </el-form-item>
              <el-form-item label="订单状态：" prop="splittingStatus">
                <el-select
                  v-model="updateForm.splittingStatus"
                  filterable
                  disabled
                >
                  <el-option
                    v-for="dict in dicts[DictDirection.包裹状态]"
                    :key="dict.dictValue"
                    :value="dict.dictValue"
                    :label="dict.dictLabel"
                  ></el-option>   
                </el-select>
              </el-form-item>
              <el-form-item label="主转单号：" prop="mainTransferOrderNo">
                <el-input v-model="updateForm.mainTransferOrderNo">
                  <i :icon="Edit" @click="mainTransferOrderNoOpen"></i>
                </el-input>
              </el-form-item>
              <el-form-item label="子转单号：" prop="transferOrderNo">
                <el-input v-model="updateForm.transferOrderNo">
                  <i :icon="Edit" @click="transferOrderNoDialogVisible = true"></i>
                </el-input>
              </el-form-item>   
              <el-form-item style="width: 560px;" label="备注：" prop="remarks">
                <el-input
                  v-model="updateForm.remarks" 
                  style="width: 392px;"
                  type="textarea" 
                ></el-input>   
              </el-form-item>
              <span class="notes">如果对应收费用信息有操作,请在备注栏加上备注</span>
              <el-form-item>
                <el-button type="primary" @click="handleEdit">修改</el-button>
              </el-form-item>
              <el-divider></el-divider>
              <el-col :span="24">
                <el-row>
                  <el-col :span="24">
                    <el-row>
                      <el-col :span="24" class="mb8">收货信息</el-col>
                      <el-col :span="24">
                        <el-form-item label="客户简称" prop="customerCode">
                          <el-select
                            v-model="updateForm.customerCode"
                           
                            filterable
                            placeholder="请选择客户"
                            clearable
                          >
                            <el-option
                              v-for="dict in dicts[DictDirection.客户]"
                              :key="dict.customerCode"
                              :label="dict.customerName"
                              :value="dict.customerCode"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                        <el-form-item label="销售产品：" prop="marketProducts">
                          <el-select
                            v-model="updateForm.marketProducts"
                            filterable
                           
                            placeholder="请输入销售产品"
                            clearable
                          >
                            <el-option
                              v-for="dict in dicts[DictDirection.产品]"
                              :key="dict.salesProductCode"
                              :label="dict.salesProductName"
                              :value="dict.salesProductCode"
                            ></el-option>
                          </el-select>
                        </el-form-item>   
                        <el-form-item label="渠道" prop="upsOrFedex" style="margin-left: 10px;">
                          <el-select
                            v-model="updateForm.upsOrFedex" 
                            filterable
                            placeholder="请选择"
                            disabled
                          >
                            <el-option label="ups" value="ups"></el-option>
                            <el-option label="fedex" value="fedex"></el-option>
                          </el-select>
                        </el-form-item>
                        <el-form-item label="收货类型：" prop="goodsType">
                          <el-select
                            v-model="updateForm.goodsType"
                            filterable
                           
                            placeholder="请选择货物类型"
                          >
                            <el-option
                              v-for="dict in dicts[DictDirection.货物类型]"
                              :key="dict.dictValue"
                              :label="dict.dictLabel"
                              :value="dict.dictValue"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                        <el-form-item label="所属机构：" prop="receivingSite">
                          <el-select
                            v-model="updateForm.receivingSite"
                            filterable
                           
                            placeholder="请选择"
                          >
                            <el-option
                              v-for="dict in dicts[DictDirection.收货站点]"
                              :key="dict.deptId"
                              :label="dict.deptName"
                              :value="dict.deptId"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                        <el-form-item label="收货时间：" prop="orderTime">
                          <el-date-picker
                            v-model="updateForm.orderTime"
                            disabled
                            type="date"
                            placeholder="选择日期"
                            format="YYYY-MM-DD"
                            value-format="YYYY-MM-DD"
                          ></el-date-picker>
                        </el-form-item>
                        <el-form-item label="总计实重：" prop="receivingTotalWeight">
                          <el-input v-model="updateForm.receivingTotalWeight" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="总体积重：" prop="receivingTotalWood">
                          <el-input v-model="updateForm.receivingTotalWood" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="总计费重：" prop="receivingTotalCharging">
                          <el-input v-model="updateForm.receivingTotalCharging" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="总件数：" prop="receivingTotal">
                          <el-input v-model="updateForm.receivingTotal" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="收货材积系数：" prop="receivingWoodCoefficient">
                          <el-input v-model="updateForm.receivingWoodCoefficient" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="收货体积系数：" prop="receivingVolumeCoefficient">
                          <el-input v-model="updateForm.receivingVolumeCoefficient" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="收货计重规则：" prop="receivingWeightRule">
                          <el-select
                            v-model="updateForm.receivingWeightRule"
                            filterable
                            
                            placeholder=""
                            disabled
                          >
                            <el-option
                              v-for="dict in dicts[DictDirection.计重规则]"
                              :key="dict.dictValue"
                              :value="dict.dictValue"
                              :label="dict.dictLabel"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                        <el-form-item label="服务商简称：" prop="serviceAbbreviation">
                          <el-input v-model="updateForm.serviceAbbreviation" disabled></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-divider></el-divider>
                  </el-col>
                  <el-col :span="24">
                    <el-row>
                      <el-col :span="24" class="mb8">出货信息</el-col>
                      <el-col :span="24">
                        <el-form-item label="客户单号：" prop="waybillNo">
                          <el-input v-model="updateForm.waybillNo" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="服务渠道：" prop="serviceChannelcode">
                          <el-input v-model="updateForm.serviceChannelcode" disabled></el-input>
                        </el-form-item>   
                        <el-form-item label="出货时间：" prop="shipmentTime">
                          <el-date-picker
                            v-model="updateForm.shipmentTime"
                            type="date"
                            disabled   
                            placeholder="选择日期"
                            format="YYYY-MM-DD"
                            value-format="YYYY-MM-DD"
                          ></el-date-picker> 
                        </el-form-item>
                        <el-form-item label="总计实重：" prop="shipmentTotalWeight">
                          <el-input v-model="updateForm.shipmentTotalWeight" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="总体积重：" prop="shipmentTotalWood">
                          <el-input v-model="updateForm.shipmentTotalWood" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="总计费重：" prop="shipmentTotalCharging">
                          <el-input v-model="updateForm.shipmentTotalCharging" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="总件数：" prop="shipmentTotal">
                          <el-input v-model="updateForm.shipmentTotal" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="成本金额：" prop="payableAmount">
                          <el-input
                            v-model="updateForm.payableAmount"
                            disabled
                            :controls="false"
                          ></el-input>
                        </el-form-item>
                        <el-form-item label="清关时间：" prop="cle   aranceTime">
                          <el-date-picker
                            v-model="updateForm.clearanceTime"
                            disabled   
                            type="date"
                            placeholder="选择日期"
                            format="YYYY-MM-DD"
                            value-format="YYYY-MM-DD"
                          /> 
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </el-col>
                </el-row>
                <el-divider></el-divider>
              </el-col>
              <el-col :span="24">
                <el-row>
                  <el-col :span="12">
                    <el-row>
                      <el-col :span="24" class="mb8">收件人信息</el-col>
                      <el-col :span="24">
                        <el-form-item label="国家：" prop="consigneeCountry">
                          <el-select
                            v-model="updateForm.consigneeCountry"
                            filterable
                            placeholder="请输入内容"
                          >
                            <el-option
                              v-for="dict in dicts[DictDirection.国家]"
                              :key="dict.countryCode"
                              :label="dict.countryChName"
                              :value="dict.countryCode"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                        <el-form-item label="姓名：" prop="consigneeName">
                          <el-input v-model="updateForm.consigneeName" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="邮编：" prop="consigneePostcode">
                          <el-input v-model.trim="updateForm.consigneePostcode" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="公司：" prop="consigneeCompany">
                          <el-input
                            v-model="updateForm.consigneeCompany"
                            auto-complete="on"
                            disabled
                          ></el-input>
                        </el-form-item>
                        <el-form-item label="城市：" prop="consigneeCity">
                          <el-input v-model="updateForm.consigneeCity" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="省州：" prop="provinceStateCode">
                          <el-input v-model="updateForm.provinceStateCode" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="电话：" prop="consigneeTel">
                          <el-input
                            v-model="updateForm.consigneeTel"
                            auto-complete="on"
                            disabled
                          ></el-input>
                        </el-form-item>
                        <el-form-item label="地址1：" prop="consigneeAddress">
                          <el-input
                            v-model="updateForm.consigneeAddress"
                            disabled
                            type="textarea"
                            :autosize="{ minRows: 2, maxRows: 4 }"
                          ></el-input>
                        </el-form-item>
                        <el-form-item label="地址2：" prop="consigneeAddress2">
                          <el-input
                            v-model="updateForm.consigneeAddress2"
                            type="textarea"
                            disabled
                            :autosize="{ minRows: 2, maxRows: 4 }"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </el-col>
                  <el-col :span="12">
                    <el-row>
                      <el-col :span="24" class="mb8">货物图片</el-col>
                      <el-col :span="24">
                        <el-scrollbar style="height: 400px;">
                          <div class="imgContainer">
                            <div v-if="title=='订单详情'">
                              <div v-for="item in updateForm.goodsList" :key="item">
                                <el-image :src="item"></el-image>
                              </div> 
                            </div>
                            <div v-if="title=='修改订单'">
                              <el-upload
                                ref="imgupload"
                                action="#"
                                list-type="picture-card"
                                multiple
                                accept=".jpg,.pdf"
                                :file-list="fileList"
                                :auto-upload="false"
                                :on-remove="handleRemove"
                                :on-change="handleFileChange"
                              >
                                <el-icon><Plus /></el-icon>
                              </el-upload>
                              <div style="float: right;"><el-button type="primary" @click="uploadImg">上传</el-button></div>
                            </div>
                          </div>
                        </el-scrollbar>
                      </el-col>
                    </el-row>
                  </el-col>
                </el-row>
                <el-divider></el-divider>
              </el-col>
              <el-col :span="24" class="mb8">
                <el-row class="mb8">
                  <el-col>品类信息</el-col>
                  <el-col :span="24">
                    <categoryInfo ref="cateRef" />
                    <el-divider></el-divider>
                  </el-col>
                </el-row>
              </el-col>

              <div v-if="title=='订单详情'">
                <el-col :span="24" class="mb8">
                  <el-row class="mb8">
                    <el-col>包裹信息</el-col>
                    <el-col style="height: 445px;">
                      <el-table
                        ref="table"
                        border   
                        :data="updateForm.shipmentWoodInfo"
                        height="400"
                        class="mb8"
                        :summary-method="getSummaries"
                        show-summary
                      >
                        <el-table-column
                          label="序号"
                          align="center"
                          type="index"
                          width="50"
                        ></el-table-column>
                        <el-table-column label="箱号" align="center" prop="caseNumber"></el-table-column>
                        <el-table-column label="长(cm)" align="center" prop="length"></el-table-column>
                        <el-table-column label="宽(cm)" align="center" prop="width"></el-table-column>
                        <el-table-column label="高(cm)" align="center" prop="height"></el-table-column>
                        <el-table-column label="实重(kg)" align="center" prop="weight"></el-table-column>
                        <el-table-column label="计费重" align="center" prop="jWeight"></el-table-column>
                        <el-table-column label="收货体积重" align="center" prop="volumeWeightTotal"></el-table-column>
                        <el-table-column label="材积重" align="center" prop="vWeight"></el-table-column>
                        <!-- <el-table-column label="件数" align="center" prop="pieceNumber"></el-table-column> -->
                        <el-table-column
                          label="收货站点"
                          align="center"
                          prop="site"
                          :formatter="(row) => dicts.getDictLabel({ dict: DictDirection.收货站点, value: row.site })"
                        >
                        </el-table-column>
                        <el-table-column
                          label="状态"
                          align="center"
                          prop="status"
                          :formatter="(row) => dicts.getDictLabel({ dict: DictDirection.包裹状态, value: row.status })"
                        ></el-table-column>
                      </el-table>
                    </el-col>
                  </el-row>
                </el-col>
              </div>
              <div v-if="title=='修改订单'">
                <el-col :span="24" class="mb8">
                  <el-row class="mb8">
                    <el-col>包裹信息</el-col>
                    <el-col>
                      <el-form
                        :inline="true"
                        :model="formInline"
                        class="demo-form-inline"
                        label-width="80px"
                      >
                        <el-form-item label="开始行：">
                          <el-input v-model.number="formInline.startRow"></el-input>
                        </el-form-item>
                        <el-form-item label="结束行：">
                          <el-input v-model.number="formInline.endRow"></el-input>
                        </el-form-item>
                        <el-form-item label="长：">
                          <el-input v-model="formInline.length" type="number"></el-input>
                        </el-form-item>
                        <el-form-item label="宽：">
                          <el-input v-model="formInline.width" type="number"></el-input>
                        </el-form-item>
                        <el-form-item label="高：">
                          <el-input v-model="formInline.height" type="number"></el-input>
                        </el-form-item>
                        <el-form-item label="实重：">
                          <el-input v-model="formInline.weight" type="number"></el-input>
                        </el-form-item>
                        <el-form-item style="margin-left: 20px;">
                          <el-button type="primary" @click="batch('修改')">批量修改</el-button>
                        </el-form-item>
                        <el-form-item style="margin-left: 40px;">
                          <el-button type="primary" @click="batch('新增')">批量新增</el-button>
                        </el-form-item>
                        <el-form-item style="margin-left: 40px;">
                          <el-button type="danger" @click="batch('删除')">批量删除</el-button>
                        </el-form-item>
                      </el-form>
                    </el-col>
                    <el-col :span="24">
                      <el-table
                        ref="pageTable"
                        border
                        show-summary
                        :data="updateForm.shipmentWoodInfo"
                        max-height="400"
                        class="mb8"
                        :summary-method="getSummaries"
                      >
                        <el-table-column
                          label="序号"
                          align="center"
                          type="index"
                          width="50"
                        ></el-table-column>
                        <el-table-column label="箱号" align="center" prop="caseNumber"></el-table-column>
                        <el-table-column label="长(cm)" align="center" prop="length">
                          <template #default="{ row, $index }">
                            <el-form-item
                              label-width="0"
                              :prop="`shipmentWoodInfo.${$index}.length`"
                              :rules="[
                                {
                                  validator: validatePass,
                                  message: '必填',
                                  trigger: 'blur',
                                },
                              ]"
                            >
                              <el-input-number
                                v-model="row.length"
                                :controls="false"
                                style="width: 100%;"
                                :step="0.01"
                                :min="2.54"
                              ></el-input-number>
                            </el-form-item>
                          </template>
                        </el-table-column>
                        <el-table-column label="宽(cm)" align="center" prop="width">
                          <template #default="{ row, $index }">
                            <el-form-item
                              label-width="0"
                              :prop="`shipmentWoodInfo.${$index}.width`"
                              :rules="[
                                {
                                  validator: validatePass,
                                  message: '必填',
                                  trigger: 'blur',
                                },
                              ]"
                            >
                              <el-input-number
                                v-model="row.width"
                                :controls="false"
                                :min="2.54"
                                :step="0.01"
                                style="width: 100%;"
                              ></el-input-number>
                            </el-form-item>
                          </template>
                        </el-table-column>
                        <el-table-column label="高(cm)" align="center" prop="height">
                          <template #default="{ row, $index }">
                            <el-form-item
                              label-width="0"
                              :prop="`shipmentWoodInfo.${$index}.height`"
                              :rules="[
                                {
                                  validator: validatePass,
                                  message: '必填',
                                  trigger: 'blur',
                                },
                              ]"
                            >
                              <el-input-number
                                v-model="row.height"
                                style="width: 100%;"
                                :controls="false"
                                :min="2.54"
                                :step="0.01"
                              ></el-input-number>
                            </el-form-item>
                          </template>
                        </el-table-column>
                        <el-table-column label="实重(kg)" align="center" prop="weight">
                          <template #default="{ row, $index }">
                            <el-form-item
                              label-width="0"
                              :prop="`shipmentWoodInfo.${$index}.weight`"
                              :rules="[
                                {
                                  validator: validatePass,
                                  message: '必填',
                                  trigger: 'blur',
                                },
                              ]"
                            >
                              <el-input-number
                                v-model="row.weight"
                                :controls="false"
                                style="width: 100%;"
                                :min="0"
                                :step="0.01"
                              ></el-input-number>
                            </el-form-item>
                          </template>
                        </el-table-column>
                        <el-table-column label="计费重" align="center" prop="jWeight"></el-table-column>
                        <el-table-column label="收货体积重" align="center" prop="volumeWeightTotal"></el-table-column>
                        <el-table-column label="材积重" align="center" prop="vWeight"></el-table-column>
                       
                        <el-table-column label="操作" align="center">
                          <template #default="{ row, $index }">
                            <el-button
                              :icon="Delete"
                              type="primary"
                              text
                              @click="handleDeletePackage(row, $index)"
                            >
                              删除
                            </el-button>
                          </template>
                        </el-table-column>
                      </el-table>
                    </el-col>
                  </el-row>
                  <el-row :gutter="10">
                    <el-col :span="1.5">
                      <el-button
                        :icon="Plus"
                        
                        type="primary"
                        @click="handleAddPage"
                      >
                        增加
                      </el-button>
                    </el-col>
                  </el-row>
                  <el-divider></el-divider>
                </el-col>
              </div>
              <el-col :span="24">
                <el-row>
                  <el-col :span="24" class="mb8">
                    <div class="mb8">货物追踪详细信息</div>
                  </el-col>
                  <el-col :span="24" class="myScrollbar">
                    <el-table :data="trajectoryList" max-height="500px" border>
                      <el-table-column align="center" label="原始轨迹" prop="description"></el-table-column>
                      <el-table-column align="center" label="日期" prop="day"></el-table-column>
                      <el-table-column align="center" label="操作人" prop="name"></el-table-column>
                      <el-table-column align="center" label="轨迹内容" prop="operableTrack">
                      </el-table-column>
                      <el-table-column
                        label="备注"
                        align="center"
                        prop="remarks"
                        show-overflow-tooltip
                      ></el-table-column>
                    </el-table>
                  </el-col>
                </el-row>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
      </el-form>
      <div v-if="title=='修改订单'" class="btnsContainer">
        <el-button type="primary" @click="submitForms">确定修改</el-button>
        <el-button type="primary" @click="cancel">取消</el-button>
      </div>
      <div v-if="title=='订单详情'" class="btnsContainer">
        <el-button type="primary" @click="cancel">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script lang="ts" setup>
import { ref, getCurrentInstance, defineAsyncComponent, defineEmits } from 'vue'
import { Edit, Delete, Plus } from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox, ElButton } from 'element-plus'
import useDicts, { DictDirection } from '@/store/modules/dicts'
import { checkoutDetails } from '@/api/expressManager/fedex'
import { editOrder } from '@/api/expressManager/external'
import { fedexOrderNo } from '@/api/expressManager/orderList'

const emit = defineEmits(['refush'])
const categoryInfo = defineAsyncComponent(() => import('./categoryInfo.vue'))
const dicts = useDicts()
dicts.setDicts(DictDirection.报价类型)
dicts.setDicts(DictDirection.计重规则)
dicts.setDicts(DictDirection.国家)
const { proxy } = getCurrentInstance() as any
const open = ref(false)
const title = ref(null)
const loading = ref(false)
const updateForms = ref(undefined)
const imgupload = ref(undefined)
const updateForm = ref({
  orderNo: '',
  quotationType: '',
  customPrice: '',
  checkInMer: '',
  businessManager: '',
  splittingStatus: '',
  mainTransferOrderNo: '',
  transferOrderNo: '',
  remarks: '',
  customerCode: '',
  marketProducts: '',
  upsOrFedex: '',
  goodsType: '',
  receivingSite: '',
  orderTime: '',
  receivingTotalWeight: '',
  receivingTotalWood: '',
  receivingTotalCharging: '',
  receivingTotal: '',
  receivingWoodCoefficient: '',
  receivingVolumeCoefficient: '',
  receivingWeightRule: '',
  serviceAbbreviation: '',
  waybillNo: '',
  serviceChannelcode: '',
  shipmentTime: '',
  shipmentTotalWeight: '',
  shipmentTotalWood: '',
  shipmentTotalCharging: '',
  shipmentTotal: '',
  payableAmount: '',
  clearanceTime: '',
  consigneeCountry: '',
  consigneeName: '',
  consigneePostcode: '',
  consigneeCompany: '',
  consigneeCity: '',
  provinceStateCode: '',
  consigneeTel: '',                   
  consigneeAddress: '',
  consigneeAddress2: '',
  goodsList: [],
  shipmentWoodInfo: [],
})
const formInline = ref({
  startRow: '',
  endRow: '',
  length: '',
  width: '',
  height: '',
  weight: '',
})
const clearFormInline = () => {
  proxy.formInline = {
    startRow: '',
    endRow: '',
    length: '',
    width: '',
    height: '',
    weight: '',
  }
}
const batch = (v) => {
  if (v.includes('修改')) {
    if (proxy.formInline.startRow && proxy.formInline.endRow && proxy.formInline.endRow > proxy.formInline.startRow) {
      proxy.updateForm.shipmentWoodInfo.forEach((v, i) => {
        if (i + 1 <= proxy.formInline.endRow && i + 1 >= proxy.formInline.startRow) {
          const { height, length, weight, width } = proxy.formInline
          v.height = height || v.height
          v.length = length || v.length
          v.weight = weight || v.weight
          v.width = width || v.width
        }
      })
      clearFormInline()
    } else {
      ElMessage.error('批量修改必须要输入开始行和结束行,并且结束行要大于开始行！')
    }
  } else if (v.includes('新增')) {
    if (proxy.formInline.endRow && (proxy.formInline.height || proxy.formInline.length || proxy.formInline.weight || proxy.formInline.width)) {
      for (let i = 0; i < proxy.formInline.endRow; i++) {
        proxy.updateForm.shipmentWoodInfo.push({
          height: proxy.formInline.height || '',
          length: proxy.formInline.length || '',
          weight: proxy.formInline.weight || '',
          width: proxy.formInline.width || '',
        })
      }
      clearFormInline()
    } else {
      proxy.$message.error('批量新增必须要输结束行和长、宽、高、重中任意一项！')
    }
  } else if (v.includes('删除')) {
    if (proxy.formInline.startRow && proxy.formInline.endRow && proxy.formInline.endRow > proxy.formInline.startRow) {
      proxy.$confirm(`此操作将永久删除${ proxy.formInline.startRow }-${ proxy.formInline.endRow }条记录, 是否继续?", "警告`, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
      .then(() => {
        proxy.updateForm.shipmentWoodInfo.splice(proxy.formInline.startRow - 1, proxy.formInline.endRow - (proxy.formInline.startRow - 1))
        proxy.$message({
          type: 'success',
          message: '删除成功!',
        })
        clearFormInline()
      })
      .catch(() => {
        ElMessage({
          type: 'info',
          message: '已取消删除',
        })
      })
    } else {
      ElMessage.error('批量删除必须要输入开始行和结束行,并且结束行要大于开始行！')
    }
  }
}
const refush = () => {
  emit('refush')
}
const trajectoryList = ref([])
const cateRef = ref(null)
const transferOrderNoDialogVisible = ref(false)
const mainTransferOrderNoOpen = () => {

}
const fileList = ref([])
const handleRemove = (file, fileList) => {
  fileList.value = fileList
}
const handleFileChange = (file, fileList) => {
  fileList.value = fileList
}
const uploadImg = () => {
  
}
const submitForms = () => {
  proxy.updateForm.woodInfoList = proxy.updateForm.shipmentWoodInfo
  const newForm = JSON.parse(JSON.stringify(proxy.updateForm))
  newForm.receivingWoodInfo = JSON.stringify(newForm.shipmentWoodInfo)
  newForm.shipmentWoodInfo = JSON.stringify(newForm.shipmentWoodInfo)
  newForm.id = idss.value
  editOrder(newForm).then(res => {
    if (res.code == 200) {
      ElMessage.success('修改成功')
      cancel()
      refush()
    } else {
      ElMessage.error(res.msg)
    }
  })
}
const cancel = () => {
  open.value = false
  proxy.$refs.updateForms.resetFields()
  proxy.$refs.imgupload.resetFields()
}
const getSummaries = () => ['合计', '', '', '', '', proxy.updateForm.receivingTotalWeight, proxy.updateForm.receivingTotalCharging, '', proxy.updateForm.receivingTotalWood]
const handleEdit = () => {}
const labels = ref(null)
const cancle = () => {
  open.value = false
  proxy.$refs.updateForms.resetFields()
}
const handleDeletePackage = (row, index) => {}
const handleAddPage = () => {
  updateForm.value.shipmentWoodInfo.push({})
}
const idss = ref(null)
const orderNos = ref(null)
const initData = () => {
  const id = idss.value
  const data = orderNos.value
  loading.value = true
  checkoutDetails(id).then(res => {
    if (res.code == 200) {
      res.data.quotationType = String(res.data.quotationType)
      res.data.shipmentWoodInfo = JSON.parse(res.data.receivingWoodInfo)
      updateForm.value = res.data
      loading.value = false
    }
  }).catch(() => {
    loading.value = false
  })
  fedexOrderNo(data).then(res => {
    if (res.code == 200) {
      trajectoryList.value = res.data
      loading.value = false
    } else {
      loading.value = false
    }
  })
  cateRef.value.orderNoss = orderNos.value
  cateRef.value.init()
}
const validatePass = (rule, value, callback) => {
  if (value === '' || value == 0 || value == undefined) {
    callback(new Error('请输入包裹信息'))
  } else {
    callback()
  }
}
defineExpose({
  open,
  title,
  initData,
  loading,
  idss,
  orderNos,
})
</script>
<style lang="less" scoped>
/deep/.el-input__wrapper {
  width: 200px;
}
.notes {
  color: red;
  display: block;
  height: 40px;
  line-height: 40px;
  margin-right: 10px;
}
.btnsContainer {
  position: fixed;
  bottom: 0;
  z-index: 999;
  right: 18px;
  margin-bottom: 18px;
}

</style>